package sort.impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

public class InsertionSorter extends AbstractSorter {

    public InsertionSorter() {
        super(SorterType.INSERTION);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        sort(tComparator, ts, 0, ts.size());
    }


    public <T>void sort(Comparator<T> tComparator, List<T> ts, int left, int right) {
        for (int i = left; i < right; i++) {
            int j = i;
            while ((j > left) && (greater(tComparator,ts,j-1,j))){
                swap(ts,j,j-1);
                j--;
            }
        }
    }
}

